import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    component: () => import('@/layouts/AdminLayout.vue'),
    redirect: '/dashboard',
    children: [
      {
        path: '/dashboard',
        name: 'Dashboard',
        component: () => import('@/views/Dashboard.vue'),
        meta: { title: 'Dashboard' }
      },
      {
        path: '/categories',
        name: 'Categories',
        component: () => import('@/views/Categories.vue'),
        meta: { title: 'Categories' }
      },
      {
        path: '/products',
        name: 'Products',
        component: () => import('@/views/Products.vue'),
        meta: { title: 'Products' }
      },
      {
        path: '/products/create',
        name: 'CreateProduct',
        component: () => import('@/views/ProductForm.vue'),
        meta: { title: 'Create Product' }
      },
      {
        path: '/products/edit/:id',
        name: 'EditProduct',
        component: () => import('@/views/ProductForm.vue'),
        meta: { title: 'Edit Product' }
      },
      {
        path: '/messages',
        name: 'Messages',
        component: () => import('@/views/Messages.vue'),
        meta: { title: 'Contact Messages' }
      },
      {
        path: '/store-settings',
        name: 'StoreSettings',
        component: () => import('@/views/StoreSettings.vue'),
        meta: { title: 'Store Settings' }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  document.title = `${to.meta.title || 'Admin'} - Lucy African Fashion`
  next()
})

export default router

